package com.goods.controller.business;

import com.goods.business.service.SupplierService;
import com.goods.common.model.business.Supplier;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.SupplierVO;
import com.goods.common.vo.system.PageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Api(tags = "业务模块-物资来源相关接口")
@RestController
@RequestMapping("/business/supplier")
public class SupplierController {

    @Autowired
    private SupplierService supplierService;

    //2.1 /findSupplierList?pageNum=1&pageSize=10&name=
    @ApiOperation(value = "物资来源列表")
    @GetMapping("/findSupplierList")
    public ResponseBean<PageVO<SupplierVO>> findSupplierList(@RequestParam Map<String, String> paramMap) {
        PageVO<SupplierVO> pageVO = supplierService.findSupplierList(paramMap);
        return ResponseBean.success(pageVO);
    }

    // /add  添加物资来源
    @ApiOperation(value = "添加物资来源")
    @PostMapping("/add")
    public ResponseBean addSupplierList(@RequestBody SupplierVO supplierVO) {
        supplierService.addSupplierList(supplierVO);
        return ResponseBean.success();
    }
    // /edit   //2.3.1、回显要的编辑物资来源
    @ApiOperation(value = "回显物资来源")
    @GetMapping("/edit/{id}")
    public ResponseBean editSupplier(@PathVariable Long id) {
        Supplier supplier = supplierService.editSupplier(id);
        return ResponseBean.success(supplier);
    }
    // /update/24  //2.3.2、修改要的编辑物资来源
    @ApiOperation(value = "修改要的编辑物资来源")
    @PutMapping("/update/{id}")
    public ResponseBean updateSupplier(@PathVariable Long id, @RequestBody Supplier supplier) {
        supplierService.updateSupplier(id,supplier);
        return ResponseBean.success();
    }
    // /delete/24  2.4、删除物资来源
    @ApiOperation(value = "删除物资来源")
    @DeleteMapping("/delete/{id}")
    public ResponseBean deleteSupplier(@PathVariable Long id) {
        supplierService.deleteSupplier(id);
        return ResponseBean.success();
    }
}
